﻿/*
*  封装的对象模型
*/
function GetSmJSON(URL, PARAM, SUCCESSFUN) {
    $.ajax({
        async: false,
        url: URL,
        type: "POST",
        dataType: "json",
        data: PARAM,
        contentType: "application/json; charset=utf-8",
        success: function (json) {
            SUCCESSFUN(json.d);
        },
        error: function (x, e) {
        }
    });
};
//哈希表
function SmHashtable() {
    this.Data = undefined;
    this.Init = function (url, param) {
        var sf = this;
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    this.GetValue = function (field) {
        var sf = this;
        for (var i in sf.Data) {
            if (sf.Data[i].Key == field) return sf.Data[i].Value;
        }
        return "";
    };
};

//SmObjectData对象模型
function SmObjectData(dbalias, tablename) {
    this.ID = 0;
    this.Key = "";
    this.TableName = tablename;
    this.DBAlias = dbalias;
    this.Data = undefined;
    this.Init = function (key, id) {
        var sf = this;
        sf.Key = key;
        sf.ID = id;
        var url = DBCenterServiceUrl + "/Core.asmx/GetSmObjectData";
        var param = "{'DBAlias':'" + this.DBAlias + "','tablename':'" + this.TableName + "','key':'" + this.Key + "','id':'" + this.ID + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
            sf.Data.DBAlias = sf.DBAlias;
            sf.Data.TableName = sf.TableName;
        });
    };
    this.GetFirstSmObject = function (condition) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetFirstSmObject";
        var param = "{'dbalias':'" + sf.DBAlias + "','tablename':'" + sf.TableName + "','condition':'" + condition + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
            sf.Data.DBAlias = sf.DBAlias;
            sf.Data.TableName = sf.TableName;
        });
    };
    this.GetValue = function (field) {
        for (var i in this.Data.Data) {
            if (this.Data.Data[i].Key == field) return this.Data.Data[i].Value;
        }
        return "";
    };
    this.SetValue = function (field, value) {
        for (var i in this.Data.Data) {
            if (this.Data.Data[i].Key == field) {
                this.Data.Data[i].Value = value;
                return true;
            }
        }
        return false;
    };
    this.Save = function (service, param1) {//'a':'v','b':'v'
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        if (param1 != undefined) {
            param = "{'json':'" + JSON.stringify(this.Data) + "'," + param1 + "}";
        }
        var res = false;
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
    //通用的方法，把表和数据库别名加进去，后台统一保存，不用每个都写自己的服务
    this.Update = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = DBCenterServiceUrl + "/Core.asmx/UpdateSmObject";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
    this.UpdateObj = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = DBCenterServiceUrl + "/Core.asmx/UpdateSmObj";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
    this.UpdateTKQ = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = DBCenterServiceUrl + "/Core.asmx/UpdateSmObjectTKQ";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
    this.Delete = function () {
        var param = "{'json':'" + JSON.stringify(this.Data) + "'}";
        var res = false;
        service = DBCenterServiceUrl + "/Core.asmx/DeleteSmObject";
        GetSmJSON(service, param, function (txt) {
            res = txt;
        });
        return res;
    };
};

//SmPageData对象模型
function SmPageData(dbalias, tablename,pagesize) {
    this.DBAlias = dbalias;
    this.TableName = tablename;
    this.Key = "";
    this.Fields = "*";
    this.Data = undefined;
    this.PageSize =pagesize|| 5;
    this.PageIndex = 1;
    this.Filter = "";
    this.SelectedID = 0;
    this.PageCount = 1;
    this.RecordCount = 1;
    this.ColumnCount = 1;
    this.PageRecordCount = 1;
    this.OrderBy = "";
    this.OrderByType = 0;
    this.InitEx = function () {
        this.Init(this.Key, this.Fields, this.Filter);
    }
    //主键key,字段*,条件""
    this.Init = function (key, fields, filter, orderby, orderbytype) {
        var sf = this;
        sf.Key = key;
        sf.Fields = fields;
        sf.Filter = filter;
        if (orderby == undefined) {
            sf.OrderBy = key;
        }
        else {
            sf.OrderBy = orderby;
        }
        if (orderbytype == undefined) {
            sf.OrderByType = 0;
        }
        else {
            sf.OrderByType = orderbytype;
        }
        var url = DBCenterServiceUrl + "/Core.asmx/GetSmPageData";
        var param1 = "{'DBAlias':'" + sf.DBAlias + "',";
        param1 += "'tablename':'" + sf.TableName + "',";
        param1 += "'key':'" + sf.Key + "',";
        param1 += "'selectfield':'" + sf.Fields + "',";
        param1 += "'filter':'" + sf.Filter + "',";
        param1 += "'orderby':'" + sf.OrderBy + "',";
        param1 += "'orderbytype':'" + sf.OrderByType + "',";
        param1 += "'pagesize':'" + sf.PageSize + "',";
        param1 += "'pageindex':'" + sf.PageIndex + "'"
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.PageCount = sf.Data.PageCount;
                sf.RecordCount = sf.Data.RecordCount;
                sf.ColumnCount = sf.Data.ColumnCount;
                sf.PageRecordCount = sf.Data.PageRecordCount;
            }
        });
    };
    this.Refresh = function () {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetSmPageData";
        var param1 = "{'DBAlias':'" + sf.DBAlias + "',";
        param1 += "'tablename':'" + sf.TableName + "',";
        param1 += "'key':'" + sf.Key + "',";
        param1 += "'selectfield':'" + sf.Fields + "',";
        param1 += "'filter':'" + sf.Filter + "',";
        param1 += "'orderby':'" + sf.OrderBy + "',";
        param1 += "'orderbytype':'" + sf.OrderByType + "',";
        param1 += "'pagesize':'" + sf.PageSize + "',";
        param1 += "'pageindex':'" + sf.PageIndex + "'"
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.PageCount = sf.Data.PageCount;
                sf.RecordCount = sf.Data.RecordCount;
                sf.ColumnCount = sf.Data.ColumnCount;
                sf.PageRecordCount = sf.Data.PageRecordCount;
            }
        });
    };
    this.PageDown = function () {
        if (this.Data != undefined) {
            this.PageIndex++;
            if (this.PageIndex > this.Data.PageCount) {
                this.PageIndex = this.Data.PageCount;
            }
            this.Init(this.Key, this.Fields, this.Filter);
        }
    };
    this.PageUp = function () {
        if (this.Data != undefined) {
            this.PageIndex--;
            if (this.PageIndex < 1) {
                this.PageIndex = 1;
            }
            this.Init(this.Key, this.Fields, this.Filter);
        }
    };
    this.First = function () {
        if (this.Data != undefined) {
            this.PageIndex = 1;
            this.Init(this.Key, this.Fields, this.Filter);
        }
    };
    this.Last = function () {
        if (this.Data != undefined) {
            this.PageIndex = this.Data.PageCount;
            this.Init(this.Key, this.Fields, this.Filter);
        }
    };

    this.Select = function (id) {
        this.SelectedID = id;
        if (typeof this.OnSelect == "function") {
            this.OnSelect();
        }
    };
    this.GetSelectedSmObject = function () {
        var obj = new SmObjectData(this.DBAlias, this.TableName);
        obj.Init(this.Key, this.SelectedID);
        return obj;
    };

    this.GetKeyIndex = function (key) {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0) {
            for (var i = 0; i < self.ColumnCount; i++) {
                if (self.Data.Captions[i] == key) return i;
            }
        }
        return -1;
    };
};


function SmSubmit(dbalias) {
    this.DBAlias = dbalias;
    this.Init = function (sql) {
        var sf = this;
        var res = false;
        var url = DBCenterServiceUrl + "/Core.asmx/SmSubmit";
        var param1 = "{'dbalias':'" + sf.DBAlias + "',";
        param1 += "'sql':'" + sql + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            res = txt;
        });
        return res;
    };
}

//适合小数据量查询
function SmDataTable(dbalias) {
    this.DBAlias = dbalias;
    this.Data = undefined;
    this.RecordCount = 0;
    this.ColumnCount = 0;
    this.Init = function (sql) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetSmDataTable";
        var param1 = "{'dbalias':'" + sf.DBAlias + "',";
        param1 += "'sql':'" + sql + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.RecordCount = sf.Data.Rows.length;
                sf.ColumnCount = sf.Data.Captions.length;
            }
        });
    };
    this.GetKeyIndex = function (key) {
        var self = this;
        if (self.Data != undefined && self.ColumnCount > 0) {
            for (var i = 0; i < self.ColumnCount; i++) {
                if (self.Data.Captions[i] == key) return i;
            }
        }
        return -1;
    };
    this.Inquiry = function (text) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/IntelligentQuery";
        var param1 = "{'dbalias':'" + sf.DBAlias + "',";
        param1 += "'text':'" + text + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            sf.Data = JSON.parse(txt);
            if (sf.Data != undefined) {
                sf.RecordCount = sf.Data.Rows.length;
                sf.ColumnCount = sf.Data.Captions.length;
            }
        });
    };
};

//Excel
function SmExcel(dbalias, tableName) {
    this.DBAlias = dbalias;
    this.TableName = tableName;
    this.Init = function (sql, succallback, year) {
        var sf = this;
        var res = "失败";
        var url = DBCenterServiceUrl + "/Excel.asmx/ExportExcel";
        var param1 = "{'dbalias':'" + sf.DBAlias + "',";
        param1 += "'sql':'" + sql + "'";
        param1 += ",'tableName':'" + tableName + "'";
        param1 += ",'year':'" + year + "'";
        param1 += "}";
        GetSmJSONAsync(url, param1, function (txt) {
            res = txt;
        }, succallback);
    }
    this.Delete = function (path) {
        var res = false;
        var url = DBCenterServiceUrl + "/Excel.asmx/DeleteExcel";
        var param1 = "{'filePath':'" + path + "'";
        param1 += "}";
        GetSmJSON(url, param1, function (txt) {
            res = txt;
        });
        return res;
    }
}

//SmConstClsList对象
function SmConstClsList() {
    this.Data = undefined;
    this.Init = function (types) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetMetaConstList";
        var param = "{'types':'" + types + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    this.InitXZQ = function (xzqm) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetXZQConstList";
        var param = "{'xzqm':'" + xzqm + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
	this.GetDistinctList = function(dbalias,sql){
		var sf = this;
		var url = DBCenterServiceUrl + "/Core.asmx/GetDistinctList";
        var param = "{'dbalias':'" + dbalias + "','sql':'"+sql+"'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
	};
    //填充select控件,通过默认字典代码填充
    this.FillSelectHtml = function (select, type, defkey) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Key == "") {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'></option>";
                    }
                    else if (defkey != "" && obj.Key == defkey) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Key + ";" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Key + ";" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    //填充select控件,通过默认字典值填充
    this.FillSelectHtml2 = function (select, type, defValue) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (var y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Value == defValue) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    this.FillSelectHtml4 = function (select, type, defkey) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Value == "") {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'></option>";
                    }
                    else if (defkey != "" && obj.Value == defkey) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    //填充select控件行政区名称和代码
    this.FillSelectHtml3 = function (select, defkey) {
        var self = this;
        var html = "";
        for (var y in self.Data.ConstList) {
            var obj = self.Data.ConstList[y];
            if (obj.Key == defkey) {
                html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Value + "</option>";
            }
            else {
                html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Value + "</option>";
            }
        }
        select.html(html);
    };
    this.GetValue = function (key, type) {
        var strresult = "";
        if (this != null) {
            var o = null; var ii = 0;
            for (ii = 0; ii < this.Data.ConstClsList.length; ii++) {
                if (this.Data.ConstClsList[ii].Type == type) {
                    o = this.Data.ConstClsList[ii];
                    break;
                }
            }
            if (o != null) {
                for (ii = 0; ii < o.ConstList.length; ii++) {
                    if (o.ConstList[ii].Key == key) {
                        strresult = o.ConstList[ii].Value;
                        break;
                    }
                }
            }
        }
        return strresult;
    }

};

//SmConstClsList1对象
function SmConstClsList1() {
    this.Data = undefined;
    this.Init = function (types) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetMetaConstList1";
        var param = "{'types':'" + types + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    this.Init2 = function (types) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetMetaConstList2";
        var param = "{'types':'" + types + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    this.Init3 = function (types) {
        var sf = this;
        var url = DBCenterServiceUrl + "/Core.asmx/GetMetaConstList3";
        var param = "{'types':'" + types + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.Data = JSON.parse(txt);
        });
    };
    //填充select控件,通过默认字典代码填充
    this.FillSelectHtml = function (select, type, defkey) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Key == "0") {
                        html += "<option value='0'selected='true'></option>";
                    }
                    else if (defkey != "" && obj.Key == defkey) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Key + ";" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Key + ";" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    //填充select控件,通过默认字典代码填充
    this.FillSelectHtml3 = function (select, type, defkey) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Key == "") {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'></option>";
                    }
                    else if (defkey != "" && obj.Value == defkey) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    //填充select控件,通过默认字典值填充
    this.FillSelectHtml2 = function (select, type, defValue) {
        var self = this;
        for (var x in self.Data.ConstClsList) {
            var cc = self.Data.ConstClsList[x];
            if (cc.Type == type) {
                var html = "";
                for (var y in cc.ConstList) {
                    var obj = cc.ConstList[y];
                    if (obj.Value == defValue) {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "' selected='true'>" + obj.Value + "</option>";
                    }
                    else {
                        html += "<option value='" + obj.Key + "' mc='" + obj.Value + "'>" + obj.Value + "</option>";
                    }
                }
                select.html(html);
                break;
            }
        }
    };
    this.GetValue = function (key, type) {
        var strresult = "";
        if (this != null) {
            var o = null; var ii = 0;
            for (ii = 0; ii < this.Data.ConstClsList.length; ii++) {
                if (this.Data.ConstClsList[ii].Type == type) {
                    o = this.Data.ConstClsList[ii];
                    break;
                }
            }
            if (o != null) {
                for (ii = 0; ii < o.ConstList.length; ii++) {
                    if (o.ConstList[ii].Key == key) {
                        strresult = o.ConstList[ii].Value;
                        break;
                    }
                }
            }
        }
        return strresult;
    }
};

//用户登录
function SmWFStaff() {
    this.StaffID = 0; //用户ID
    this.StaffCode = ""; //用户代码
    this.StaffName = ""; //用户名
    this.IndexPage = YZTUrl + "/index.shtm";
    this.LogPage = YZTUrl + "/index.shtml"
    this.Pass = false; //是否登录成功

    //获取当前浏览器用户登录状态
    this.GetCurrentUser = function () {
        var sf = this;
        var url = WFServiceUrl + "/WFLogin.asmx/GetCurrentUser";
        var param = "{}";
        GetSmJSON(url, param, function (txt) {
            var st = JSON.parse(txt);
            sf.StaffID = st.StaffID;
            sf.StaffCode = st.StaffCode;
            sf.StaffName = st.StaffName;
            sf.Pass = st.Pass;
        });
    };

    //业务页面检测，某一用户名是否登录,没有登录则返回到登录页
    this.CheckLogin = function (user) {
        var sf = this;
        var url = WFServiceUrl + "/WFLogin.asmx/CheckLogin";
        var param = "{'user':'" + user + "'}";
        GetSmJSON(url, param, function (txt) {
            var st = JSON.parse(txt);
            sf.StaffID = st.StaffID;
            sf.StaffCode = st.StaffCode;
            sf.StaffName = st.StaffName;
            sf.Pass = st.Pass;
        });
    };
    //登录页面，成功后进入一张图框架页
    this.Login = function (user, pwd) {
        var sf = this;
        var url = WFServiceUrl + "/WFLogin.asmx/Login";
        var param = "{'user':'" + user + "','password':'" + pwd + "'}";
        GetSmJSON(url, param, function (txt) {
            var st = JSON.parse(txt);
            sf.StaffID = st.StaffID;
            sf.StaffCode = st.StaffCode;
            sf.StaffName = st.StaffName;
            sf.Pass = st.Pass;
        });
    };
    //注销，返回到登录页
    this.LogOut = function () {
        var sf = this;
        var url = WFServiceUrl + "/WFLogin.asmx/LogOut";
        var param = "{'user':'" + sf.StaffCode + "'}";
        GetSmJSON(url, param, function (txt) {
            sf.StaffID = 0;
            sf.StaffCode = "";
            sf.StaffName = "";
            sf.Pass = false;
        });
    };


}

//服务器日期
function SmDate() {
    this.Value = undefined;
    this.GetServerDate = function () {
        var sf = this;
        var url = WFServiceUrl + "/WFCore.asmx/GetCurrentDate";
        var param = "{}";
        GetSmJSON(url, param, function (txt) {
            sf.Value = txt;
        });
    }
};

//获取记录数
function GetSmRecordCount(dbalias,sql) {
	var record = 0;
	var url = DBCenterServiceUrl + "/Core.asmx/GetSmRecordCount";
	var param = "{'dbalias':'" + dbalias + "','sql':'" + sql + "'}";
	GetSmJSON(url, param, function (txt) {
		record = txt;
	});
	return record;
}

function GetServerDate() {
    var smdate = new SmDate();
    smdate.GetServerDate();
    var result=smdate.Value.replace('/','-');
    return smdate.Value;
}

//消息框
function alertex2(str, caption, p_left, p_top, waittime) {
    this.disappear = function () {
        $("#bgdiv").remove();
        $("#msgdiv").remove();
        $("#msgtitle").remove();
        msgobj = null;
        msgdiv = null;
    };
    disappear();
    if (p_left == "") {
        p_left = -115;
    }
    if (p_top == "") {
        p_top = -88;
    }
    if (!waittime ) {
        waittime = 4000;
    }
    this.m_text = str;
    this.m_caption = caption;
    this.m_width = 200;
    this.m_height = 100;
    this.m_wait = waittime;
    this.m_fade = 200;
    this.m_bordercolor = "#336699";
    this.m_titlecolor = "#99ccff";
    var msgw, msgh, bordercolor;
    msgw = m_width; //提示窗口的宽度
    msgh = m_height; //提示窗口的高度
    titleheight = 25 //提示窗口标题高度
    bordercolor = m_bordercolor; //提示窗口的边框颜色
    titlecolor = m_titlecolor; //提示窗口的标题颜色

    var swidth, sheight;
    swidth = document.body.offsetWidth;
    sheight = document.body.offsetHeight;
    if (sheight < screen.height) {
        sheight = screen.height;
    }
    // //此处可以添加一个背景，防止多次点击保存按钮
    // if(bgobj==undefined){
    // var bgobj=document.createElement("div");
    // }
    // bgobj.setAttribute('id','bgdiv');
    // bgobj.style.position="absolute";
    // bgobj.style.top="0";
    // bgobj.style.background="#777";
    // bgobj.style.filter="progid:dximagetransform.microsoft.alpha(style=3,opacity=25,finishopacity=75";
    // bgobj.style.opacity="0.6";
    // bgobj.style.left="0";
    // bgobj.style.width=swidth + "px";
    // bgobj.style.height=sheight + "px";
    // bgobj.style.zindex = "10000";
    // document.body.appendChild(bgobj);
    if (msgobj == null) {
        var msgobj = document.createElement("div");
    }
    msgobj.setAttribute("id", "msgdiv");
    msgobj.setAttribute("align", "center");
    msgobj.style.background = "white";
    msgobj.style.border = "1px solid " + bordercolor;
    msgobj.style.position = "absolute";
    msgobj.style.left = "50%";
    //    msgobj.style.top = "50%";

//    alertex(document.documentElement.offsetHeight)
//    alertex(document.documentElement.clientHeight)
//    if (document.documentElement.clientHeight < document.documentElement.offsetHeight - 4) {
//        alertex();
//    }
    msgobj.style.top = ((document.body.scrollHeight - msgh) / 2 - 195 + this.parent.document.body.scrollTop) + "px";
    msgobj.style.font = "14px/1.6em verdana, geneva, arial, helvetica, sans-serif";
    msgobj.style.marginLeft = p_left + "px"; //"-115px" ;
    msgobj.style.marginTop = p_top + document.documentElement.scrollTop + "px"; //-115+document.documentElement.scrollTop+"px";
    msgobj.style.width = msgw + "px";
    msgobj.style.height = msgh + "px";
    msgobj.style.textAlign = "center";
    msgobj.style.lineHeight = (msgh - titleheight) + "px";
    msgobj.style.zIndex = "10001";
    if (title == null) {
        var title = document.createElement("h4");
    }
    title.setAttribute("id", "msgtitle");
    title.setAttribute("align", "left");
    title.style.margin = "0";
    title.style.padding = "3px";
    title.style.background = bordercolor;
    title.style.filter = "progid:dximagetransform.microsoft.alpha(startx=20, starty=20, finishx=100, finishy=100,style=1,opacity=75,finishopacity=100);";
    title.style.opacity = "0.75";
    title.style.border = "1px solid " + bordercolor;
    title.style.height = "18px";
    title.style.font = "14px verdana, geneva, arial, helvetica, sans-serif";
    title.style.color = "white";
    title.style.cursor = "pointer";
    title.innerHTML = "消息提示";
    title.onclick = function () {
        disappear();
    }
    document.body.appendChild(msgobj);
    document.getElementById("msgdiv").appendChild(title);
    var txt = document.createElement("p");
    txt.style.margin = "1em 0"
    txt.setAttribute("id", "msgtxt");
    txt.innerHTML = str;
    document.getElementById("msgdiv").appendChild(txt);


    this.fadeout = function () {
        $("#bgdiv").fadeOut(waittime);
        $("#msgdiv").fadeOut(waittime);
        $("#msgtitle").fadeOut(waittime, function () { disappear() });
    }
    setTimeout("fadeout()", 200);
};
function alertex3(message, divclass) {
    $("#" + divclass).html(message);
        $("#"+divclass).fbmodal({
            title: "FaceBook Modal Demo",
            cancel: "Cancel",
            okay: "Okay",
            okaybutton: true,
            cancelbutton: true,
            buttons: true,
            opacity: 0.0,
            fadeout: true,
            overlayclose: true,
            modaltop: "30%",
            modalwidth: "800"
        });
     
}
function alertex(message, b) {
    //    $.messager.anim('fade', 1000);
    $.messager.show('系统提示', message, b);

}
function GetSmJSONAsync(URL, PARAM, SUCCESSFUN, succallback) {
    $.ajax({
        async: true,
        url: URL,
        type: "POST",
        dataType: "json",
        data: PARAM,
        contentType: "application/json; charset=utf-8",
        success: function (json) {
            SUCCESSFUN(json.d);
            succallback(json.d);
        },
        error: function (x, e) {
        }
    });
};


function SmExcelMB(dbalias, tableName, year) {
    this.DBAlias = dbalias;
    this.TableName = tableName;
    this.Init = function (sql, succallback) {
        var sf = this;
        var res = "失败";
        var url = DBCenterServiceUrl + "/Excel.asmx/ExportMBExcel";
        var param1 = "{'dbalias':'" + sf.DBAlias + "',";
        param1 += "'sql':'" + sql + "'";
        param1 += ",'tableName':'" + tableName + "'";
        param1 += ",'year':'" + year + "'";
        param1 += "}";
        GetSmJSONAsync(url, param1, function (txt) {
            res = txt;
        }, succallback);
    }
}

function SmCKQ() {
    this.Init = function (val, succallback) {
        var sf = this;
        var res = "失败";
        var url = DBCenterServiceUrl + "/KZ_SPDJ/CKQNJ.asmx/SaveReportFile";
        var jsonData = '{"Captions":["XKZH","ND"],"Rows":[';
        for (i = 0; i < val.length; i++) {
            jsonData += '["' + val[i][0] + '","' + val[i][1] + '"],';
        }
        jsonData = jsonData.substring(0, jsonData.length - 1);
        jsonData += ']}';
        var param1 = "{'json':'" + jsonData + "'}";
        GetSmJSONAsync(url, param1, function (txt) {
            res = txt;
        }, succallback);
    }
}

function SmTKQ() {
    this.Init = function (val, succallback) {
        var sf = this;
        var res = "失败";
        var url = DBCenterServiceUrl + "/KZ_SPDJ/CKQNJ.asmx/SaveReportFileTKQ";
        var jsonData = '{"Captions":["XKZH","ND"],"Rows":[';
        for (i = 0; i < val.length; i++) {
            jsonData += '["' + val[i][0] + '","' + val[i][1] + '"],';
        }
        jsonData = jsonData.substring(0, jsonData.length - 1);
        jsonData += ']}';
        var param1 = "{'json':'" + jsonData + "'}";
        //        var param1 = "{'xkzh':'" + xkzh + "',";
        //        param1 += "'nd':'" + Year + "'";
        //        param1 += "}";
        GetSmJSONAsync(url, param1, function (txt) {
            res = txt;
        }, succallback);
    }
}